﻿// -----------------------------------------------------------------------
// <copyright file="WebDirectoryContextTest.cs" company="USAI">
//     © 2013 Urban Science Applications, Inc. All Rights Reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace LinqToLdapExtensions.Tests.Scope
{
    using LinqToLdapExtensions.Scope;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [TestClass]
    public class WebDirectoryContextTest
    {
        private class WebDirectoryContextAccessor : WebDirectoryContext
        {
            public WebDirectoryContextAccessor(IDirectoryContextFactory directoryContextFactory)
                : base(directoryContextFactory)
            {
            }

            public IDictionary<IDirectoryContextFactory, LinqToLdap.IDirectoryContext> StorePublic
            {
                get
                {
                    return base.Store;
                }
            }
        }

        /// <summary>
        /// Verifies that create context binds correctly so that GetCurrentContext returns the same element.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void WebContextUsedInNonWebApplicationShouldThrow()
        {
            System.Web.HttpContext.Current = null;
            var factory = TestHelper.MockFactory(ScopeState.WebContext);
            var context = new WebDirectoryContextAccessor(factory);

            var store = context.StorePublic;
            Assert.IsNotNull(store);
        }
    }
}